define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shopro/lucky/record/index' + location.search,
                    add_url: 'shopro/lucky/record/add',
                    edit_url: 'shopro/lucky/record/edit',
                    del_url: 'shopro/lucky/record/del',
                    multi_url: 'shopro/lucky/record/multi',
                    import_url: 'shopro/lucky/record/import',
                    table: 'shopro_lucky_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                rowStyle: function (row, index) {
                    if (row.user.order_switch === 1) {
                        return {
                            css: {"color" : 'red !important'} // Bootstrap 浅色成功类
                        };
                    } else {
                        return {};
                    }
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'remittance.name', title: __('Remittance.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'order_num', title: __('Order_num'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'account', title: __('Account'), operate:'BETWEEN'},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'online_text', title: __('Online.name')},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'pass',
                                    text: '通过',
                                    title: '确认通过充值吗',
                                    classname: 'btn btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'shopro/lucky/record/pass',
                                    confirm: '确认通过充值吗?',
                                    visible:function(row){
                                        if(row.status == 0 && Config.passAuth){
                                            return true; //或者return false
                                        }
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    }

                                },
                                {
                                    name: 'refuse',
                                    text: '拒绝',
                                    title: '拒绝充值',
                                    classname: 'btn  btn-primary btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'shopro/lucky/record/refuse',
                                    confirm: '确认拒绝充值吗?',
                                    visible:function(row){
                                        if(row.status == 0 && Config.refuseAuth){
                                            return true; //或者return false
                                        }
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });
Table.on('dbl-click-row.bs.table', function (e, row, $element) {
  // 修改行数据
 alert(row.id);
});
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
